package com.hgw.Demo04_CreateInterator.examples;

import java.util.ArrayList;

/**
 * Data time:2021/12/18 10:55
 * StudentID:2019112118
 * Author:hgw
 * Description: 客户端测试类
 */
public class Client {
    public static void main(String[] args) {
        ArrayList<Object> products = new ArrayList<>();
        products.add("电子数码");
        products.add("生活用品");
        products.add("床上用品");
        products.add("厨房用品");

        AbstractObjectList list;
        AbstractIterator iterator;

        list = new ProductList(products);       // 创建聚合对象
        iterator = list.createIterator();       // 创建迭代器对象

        System.out.println("正向遍历：");
        while (!iterator.isLast()) {
            System.out.print(iterator.getNextItem() + ",");
            iterator.next();
        }
        System.out.println();
        System.out.println("----------------------------");
        System.out.println("逆向编程");
        while (!iterator.isFirst()) {
            System.out.print(iterator.getPreviousItem() + ",");
            iterator.previous();
        }
    }
}
